package com.xxhui.listviewdemo;

import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AbsListView;
import android.widget.TextView;

import com.xxhui.listviewdemo.Adapter.ChatItemAdapter;
import com.xxhui.listviewdemo.Bean.ChatItemBean;
import com.xxhui.listviewdemo.View.FlexibleListView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private FlexibleListView flexible;
    private TextView view;
    private ChatItemAdapter adapter;
    private String[] text = new String[]{"这是", "FlexibleListView", "距离滚动还要多少", "告诉我", "要多少中文啊", "唉", "啊勒，正能量啊喂", "对，这又能吹水了","还有几个，加油啊","多想屏幕小点啊","可惜呢。。。"};


    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        flexible = (FlexibleListView) findViewById(R.id.flexible);
        //flexible.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, ));
        adapter = new ChatItemAdapter(this,getDate());
        flexible.setAdapter(adapter);
        view = new TextView(this);
        view.setText("FlexibleListViewDemo");
        //view.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.WRAP_CONTENT));
        flexible.addHeaderView(view);
        flexible.setRecyclerListener(new AbsListView.RecyclerListener() {
            @Override
            public void onMovedToScrapHeap(View view) {

            }
        });
    }

    private List<ChatItemBean> getDate(){
        List<ChatItemBean> data = new ArrayList<ChatItemBean>();
        for(int i=1 ; i<=text.length ; i++) {
            data.add(new ChatItemBean(i%2, BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher),text[i-1]));
        }
        return data;
    }
}
